<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    年：<input type="text" id="year">
    月：<input type="text" id="month">
    日：<input type="text" id="day">
    <button id="btn">判断</button>
    <input type="text" id="result">
    <script>
        var yearInp = document.getElementById("year");
        var monthInp = document.getElementById("month");
        var dayInp = document.getElementById("day");
        var btn = document.getElementById("btn");
        var resultInp = document.getElementById("result");

        btn.onclick = function () {
            var year = yearInp.value * 1;
            var month = monthInp.value * 1;
            var day = dayInp.value * 1;
            // console.log(year,month,day);
            //  resultInp.value=test(year,month,day)
            if (test(year, month, day) == "正确") {
                resultInp.value = calc(year, month, day);
            }
            else {
                resultInp.value = test(year, month, day);
            }
        }

        function test(year, month, day) {
            var result;
            if (year >= 1000 && year <= 4000 && year % 1 == 0) {
                if (month >= 1 && month <= 12 && month % 1 == 0) {
                    var maxDay = 0;
                    switch (month) {
                        case 1:
                        case 3:
                        case 5:
                        case 7:
                        case 8:
                        case 10:
                        case 12: maxDay = 31;
                            break;
                        case 4:
                        case 6:
                        case 9:
                        case 11: maxDay = 30;
                            break;
                        default:
                            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                                maxDay = 29;
                            }
                            else {
                                maxDay = 28;
                            }
                    }
                    if (day > 0 && day <= maxDay && day % 1 == 0) {
                        result = "正确"
                    }
                    else {
                        result = "日期错误"
                    }

                }
                else {
                    result = "月份错误"
                }
            }
            else {
                result = "年份错误";
            }
            return result;
        }

        function calc(year, month, day) {
            var count = 0;
            var febDay = 28;
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                febDay = 29;
            }
            switch (month) {
                case 12: count += 30;

                case 11: count += 31;

                case 10: count += 30;

                case 9: count += 31;

                case 8: count += 31;

                case 7: count += 30;

                case 6: count += 31;

                case 5: count += 30;

                case 4: count += 31;

                case 3: count += febDay;

                case 2: count += 31;

                case 1: count += day;
                    break;
            }
            return count;
        }
    </script>
</body>

</html>